# -*- coding: utf-8 -*-
"""
类和对象：
1.属性和方法的访问权限
"""
import logging

import py_global

logger = logging.getLogger(__name__)


class Instance(object):
    class_public_attribute = 'class_public_attribute'
    _class_protected_attribute = '_class_protected_attribute'
    __class_private_attribute = '__class_private_attribute'

    def __new__(cls, attribute):
        logger.info(f'class:{cls.__name__}')
        # 重写__new__方法必须使用super初始化返回实例对象
        return super(Instance, cls).__new__(cls)

    def __init__(self, attribute):
        logger.info(f'class:{self.__class__.__name__}')
        self.attribute = attribute
        self.instance_public_attribute = 'instance_public_attribute'
        self._instance_protected_attribute = '_instance_protected_attribute'
        self.__instance_private_attribute = '__instance_private_attribute'
        pass

    def __del__(self):
        logger.info(f'class:{self.__class__.__name__}')
        pass

    def __str__(self):
        logger.info(f'class:{self.__class__.__name__}')
        return '__str__'

    def public_method(self):
        logger.info(f'class:{self.__class__.__name__}')
        pass

    def _protected_method(self):
        logger.info(f'class:{self.__class__.__name__}')
        pass

    def __private_method(self):
        logger.info(f'class:{self.__class__.__name__}')
        pass

    @classmethod
    def class_method(cls):  # 类方法
        logger.info(f'class:{cls.__name__}')
        pass

    @staticmethod
    def static_method():  # 静态方法
        pass

    @property
    def property_method(self) -> str:
        """方法转换成属性，方法必须有返回"""
        logger.info(f'class:{self.__class__.__name__}')
        return 'property_attribute_str'

    pass


if __name__ == '__main__':
    instance = Instance('attribute')

    logger.info(Instance.class_public_attribute)

    instance_protected_attribute = hasattr(instance, '_instance_protected_attribute')
    logger.info(f'instance_protected_attribute:{instance_protected_attribute}')

    # instance.__str__()
    logger.info(f'property_method:{instance.property_method}')

    del instance.attribute  # 删除属性
    del instance

    pass
